﻿using System;
using System.Data;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using DevExpress.Web.ASPxHeadline;
using DevExpress.Web.ASPxClasses;
using DevExpress.Web.ASPxCallback;
using DevExpress.Web.ASPxHtmlEditor;

using LMD.Constant;
using LMD.Lib.DataClass;
using LMD.Lib.Interface;
using LMD.Lib.Controls;

public partial class UFTSetEmail : ICPRelationshipPage
{

    public EmailBodyData m_ebd = new EmailBodyData();

    #region Properties
    public String m_sxEventId
    {
        get
        {
            if (!String.IsNullOrEmpty(Request.QueryString["eid"]))
            {
                return Request.QueryString["eid"];
            }
            else
            {
                return String.Empty;
            }
        }
    }

    #endregion Properties

    #region Event Handlers
    protected override void Page_Load(object sender, EventArgs e)
    {
        base.Page_Load(sender, e);

        Page.Title = "ICP Lintasarta: User Forum Training, Set Email";
        if (!IsPostBack && !IsCallback)
        {
            m_ebd.iEventId = int.Parse(m_sxEventId);
            m_ebd.sxHTMLEmail = DBQuery.EventTable.GetHTMLEmail(m_ebd.iEventId);
            m_ebd.sxPlainEmail = DBQuery.EventTable.GetPlainEmail(m_ebd.iEventId);
        }
        hteHTMLEmail.CreateDefaultToolbars(true);
        hteHTMLEmail.Toolbars[1].Items[0].Visible = false;
    }

    protected void cbkHTMLEmail_Callback(object sender, CallbackEventArgs e)
    {
        System.Threading.Thread.Sleep(KGlobal.AJAX_WAIT_TIME);
        e.Result = Handle_HTMLEmail(e.Parameter);
    }
    protected void cbkPlainEmail_Callback(object sender, CallbackEventArgs e)
    {
        System.Threading.Thread.Sleep(KGlobal.AJAX_WAIT_TIME);
        e.Result = Handle_PlainEmail(e.Parameter);
    }
    #endregion Event Handlers

    #region Custom Methods
    private String Handle_HTMLEmail(String sxParameter)
    {
        String sxReturn = String.Empty;

        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);

        m_ebd.iEventId = int.Parse(m_sxEventId);
        
        switch (sxSplitted[0].ToUpper())
        {
            case "EDIT":
                sxReturn = m_ebd.GetHTMLEmail();
                break;
            case "SAVE":
                m_ebd.sxHTMLEmail = sxSplitted[1];
                DBQuery.EventTable.SetHTMLEmail(m_ebd);
                sxReturn = m_ebd.GetHTMLEmail();
                break;
            case "DISCARD":
                sxReturn = m_ebd.GetHTMLEmail();
                break;
        }

        return sxReturn;
    }
    private String Handle_PlainEmail(String sxParameter)
    {
        String sxReturn = String.Empty;

        String[] sxSplitted = sxParameter.Split(new String[] { KGlobal.DELIMITER }, StringSplitOptions.None);
        m_ebd.iEventId = int.Parse(m_sxEventId);
        
        switch (sxSplitted[0].ToUpper())
        {
            case "EDIT":
                sxReturn = m_ebd.GetPlainEmail();
                break;
            case "SAVE":
                m_ebd.sxPlainEmail = sxSplitted[1];
                DBQuery.EventTable.SetPlainEmail(m_ebd);
                sxReturn = m_ebd.GetPlainEmail();
                break;
            case "DISCARD":
                sxReturn = m_ebd.GetPlainEmail();
                break;
        }

        return sxReturn;
    }
    protected override void DoSearch(String sxSearchQuery)
    {
        throw new NotImplementedException();
    }
    #endregion Custom Methods

}
